﻿using System.Collections.Generic;

namespace System.Linq.Functional
{
    public static class Initialize
    {
        // Seq.init_infinite
        public static IEnumerable<T> InitializeInfinite<T>(Func<int, T> f)
        {
            return UnfoldExtensions.Unfold(s => Option.Some(Tuple.New(f(s), s + 1)), 0);
        }

        // Seq.init_finite
        public static IEnumerable<T> InitializeFinite<T>(int count, Func<int, T> f)
        {
            return UnfoldExtensions.Unfold(s => s < count ? Option.Some(Tuple.New(f(s), s + 1)) : Option<Tuple<T, int>>.None, 0);
        }
    }
}
